﻿using Application;
using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace Web.Infrastructure.Core
{
    public class IoCControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null)
            {
                requestContext.HttpContext.Response.StatusCode = 404;
                requestContext.RouteData.Values["action"] = "NotFound";
                return new ErrorsController();
            }
            return (IController)AppEngine.Container.GetInstance(controllerType);
        }
    }
}